<form class="layui-form" action="{:url('')}" method="post" id="editForm" lay-filter="edit-form">

       <div>
            <table class="layui-table" style="width:100%" id="demo1" lay-filter="demo1">
                <thead>
                    <tr>

                        <th>物料名称</th>
                        <th>物料属性</th>
                        <th>工厂</th>
                      <th width="160">货仓/货架</th>
                        <th>物料id</th>
                        <th>库存数</th>
                    </tr>
                </thead>
                <tbody class="edit_process_body">
                    {foreach $datalist as $k => $v}
                    <tr>
                          <td>{:htmlspecialchars_decode($v['minfo']['mtype'])} {$v['minfo']['name']}<br />
<span style="font-size:12px;">物料SKU: <span class='copy-item'>{$v['minfo']['material_sku']}</span></span>
</td>
                          <td style="padding:3px 10px;">{$stock_m_type[$v['stock_m_type']]}</td>
                          <td>
                          <select name="factory_id[]" lay-ignore> 
                                {foreach $factoryKV as $k=>$fname}
                                      <option value="{$k}"  {if $v['factory_id'] == $k && $v['factory_id']>
                                      0}selected='selected'{/if}>{$fname}
                                      </option>
                                      
                                {/foreach}
                            </select>
                          </td>
                      <td style="line-height:24px;">
                      {:Form::select('storehouse_id[]', $v['storehouse_id'], $storehouseKV, '', '', 'lay-filter="storehouse-id" lay-verify="required" lay-ignore onChange="getStockPosition(this)"')}
                      {:Form::select('storeshelf_id[]',$v['storeshelf_id'], $storeshelfKV, '', 'storeshelf_id','lay-ignore')}
                      </td>
                          <td><input type="text" name="cloth_num[]" value="{$v['cloth_num']}" style="width:80px;height:32px;border:1px solid #D2D2D2;padding-left:3px;"></td>
                          <td><input type="text" name="stock[]" value="{$v['stock']}" style="width:80px;height:32px;border:1px solid #D2D2D2;padding-left:3px;">
                          <input type="hidden" name="stock_ids[]" value="{$v.id}">
                          <input type="hidden" name="material_id[]" value="{$v.material_id}">
                            <input type="hidden" name="old_stock[]" value="{$v.stock}">                          </td>
                    </tr>
                    {/foreach}
                </tbody>
            </table>
             
<div class="pop-bottom-bar">
                    <button type="submit" class="layui-btn"  btn_name="edit_one" lay-submit="" action_state='101' lay-filter="demo1">确认发货</button>
                    &nbsp;
                <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
            </div>
  </div>

    <div class="pop-bottom-bar">
    	<input type="hidden" class="field-id" name="id">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" hisi-data="{pop: true, refresh: true, callback: callbackUpdateStock}">提交修改</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>

{include file="system@block/layui" /}
    
<script>
var storeshelfMap = {:json_encode($storeshelfMap)};
layui.use(['tool', 'form', 'layer'], function() {
	var $ = layui.jquery;
	var form = layui.form;
	var layer = layui.layer;
	
	$('input[name=stock]').focus();
	
	window.calAmount = function(){
		var d = form.val("edit-form");
		var stock = 0;
		var unitPrice = 0;
		var reg = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/;
		
		if (d.stock != '') {
			if (!reg.test(d.stock)) {
				layer.msg('数量格式错误', {icon: 2,anim: 6});
				return false;
			}
			stock = layui.tool.parseFloat(d.stock, 2);
		}
		
		$('input[name=amount]').val(layui.tool.bcmul(stock, unitPrice));
	};
	
	$(document).on('blur','input[name=stock],input[name=unit_price]',function(){
		calAmount();
	});
    window.callbackUpdateStock = function(obj, res) {
		if (res.code == 1) layer.msg(res.msg, {icon: 1,end:function(){parent.layui.layer.closeAll();parent.layui.table.reload('dataTable');}});
	}
	// 货仓下拉切换
	window.getStockPosition=function(data){
		console.log(data);
		var optionArr = storeshelfMap[data.value];
		var option = '';
		for(var i in optionArr) {
			option += '<option value="'+i+'">'+optionArr[i]+'</option>';
		}
		$(data).parent().find(".storeshelf_id option").remove();
		$(data).parent().find('.storeshelf_id').append(option);
		form.render();
	};
});
</script>